﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.WinKStart;
using WMSSoft.Lib.Texte;
using WMSSoft.Lib.WinKStart.Abstract;
using WMSSoft.Lib.WinKStart.Model;
using WMSSoft.Lib.WinKStart.ViewModel;

namespace WMSSoft.WinKStart.ViewModel
{    
    public class CWinKStartStartButtonViewModel : CViewModelBase
    {
        List<CDataItem> _StartButtonModeItems = null;
        StartButtonSettings _Data = null;
        Boolean _EnableCustomButtonImage = false;

        public CWinKStartStartButtonViewModel()
        {
            try
            {
                ReadStartButtonModeItems();
            }
            catch (Exception Ex)
            {
                CMessagelogging.AppendMessage(ErrorMessages.USERSETTINGS__ERROR_UNABLE_TO_INITIALIZE_SETTINGS_STARTBUTTON_VIEWMODEL, Ex, true, EMessageTypes.Error);
            }
        }

        public CWinKStartStartButtonViewModel(StartButtonSettings Settings)
        {
            try
            {
                //base.ViewName = ViewCaption;
                _Data = Settings;
                ReadStartButtonModeItems();

                _Data.PropertyChanged += _Data_PropertyChanged;
            }
            catch (Exception Ex)
            {
                CMessagelogging.AppendMessage(ErrorMessages.USERSETTINGS__ERROR_UNABLE_TO_INITIALIZE_SETTINGS_STARTBUTTON_VIEWMODEL, Ex, true, EMessageTypes.Error);
            }
        }

        void _Data_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            try
            {
                if (e.PropertyName == "ReplaceStartButton")
                {
                    if (_Data.ReplaceStartButton == 2)
                        EnableCustomButtonImage = true;
                    else
                        EnableCustomButtonImage = false;
                }
            }
            catch (Exception Ex)
            {
                CMessagelogging.AppendMessage(ErrorMessages.USERSETTINGS__ERROR_UNABLE_TO_READ_CHANGE_STARTBUTTON_VIEWMODEL_DATA, Ex, true, EMessageTypes.Error);
            }
        }

        public StartButtonSettings Data
        {
            get { return _Data; }
        }

        public Boolean EnableCustomButtonImage
        {
            get { return _EnableCustomButtonImage; }
            set
            {
                _EnableCustomButtonImage = value;
                OnPropertyChanged("EnableCustomButtonImage");
            }
        }

        public List<CDataItem> StartButtonModeItems
        {
            get { return _StartButtonModeItems; }
            set
            {
                _StartButtonModeItems = value;
                OnPropertyChanged("StartButtonModeItems");
            }
        }

        void ReadStartButtonModeItems()
        {
            try
            {
                StartButtonModeItems = new List<CDataItem>();

                StartButtonModeItems.Add(new CDataItem("0", "Windows"));
                StartButtonModeItems.Add(new CDataItem("1", "WinKStart"));
                StartButtonModeItems.Add(new CDataItem("2", "Custom"));

                OnPropertyChanged("StartButtonModeItems");
            }
            catch (Exception Ex)
            {
                CMessagelogging.AppendMessage(ErrorMessages.USERSETTINGS__ERROR_UNABLE_TO_READ_STARTBUTTON_MODES, Ex, true, EMessageTypes.Error);
            }
        }
    }
}
